<?php
class model_checkout extends database_mysql
{
    public function mdcheckout_get_list_item($page=1,$limit=1000, $cid = null, $order_by = 'ID')
    {
        $str = null;
        if(!empty($limit))
        {
			$page=($page==0 || empty($page)?1:$page);
			$start = ($page - 1)* $limit; 
			$strlimit = "LIMIT $start, $limit";
		}
		else{
			$strlimit ='';
		}
        $sql_cid = '';	
        if($cid != null && $cid != 'all')
        {
            $sql_cid = " AND ". prefix ."check_out.CID = $cid ";
        }
        
                
        $sql = "
            SELECT *
            FROM ". prefix ."check_out
            ORDER BY ". prefix ."check_out.$order_by DESC ".$strlimit;
        $row = parent::mysql_fetch_all_rows($sql);
        parent::mysql_close_connection();
 		return $row;
    }
    
    public function mdcheckout_get_total($table, $cid = null)
    {
        $sql_cid = '';
        if($cid != null && $cid != 'all')
        {
            $sql_cid = " WHERE ". prefix ."$table.CID = $cid";
        }
        $sql = "SELECT COUNT( * ) AS total FROM ". prefix .$table . $sql_cid;
        $result = parent::mysql_select_one($sql);
        return  $result;
    }
    
    public function mdcheckout_get_item($table,$id){
        $row = parent::mysql_fetch_one_rows(" 
                    SELECT *
                    FROM
                    ". prefix .$table."
                    WHERE
                    ". prefix ."$table.ID = 
        ".$id);
 		return $row;
    }
    
    public function mdcheckout_save_data($table, $data){
        $table = prefix . $table;
        parent::mysql_insert_array($table, $data);
    }
    
    public function mdcheckout_update_data($table, $data, $condition){
        $table = prefix . $table;
        parent::mysql_update_array($table, $data, $condition);
    }
    
    public function mdcheckout_tool_func($model,$active,$str_id)
    {
        $done = false;
        switch($active)
        {
            case 'show':
            case 'hide':
                $status = array('show'=>'true', 'hide'=>'false');
                $done = $model->model_tool_set_status(prefix."check_out",$status[$active]," ID IN(".trim($str_id).")");
                
            break;

            case 'delete':
                $done = $model->model_tool_delete(prefix."check_out"," ID IN(".trim($str_id).")" );
            break;
        }

        return $done;
    }
    
}